package com.xxx.coll;

import com.sun.org.apache.regexp.internal.RE;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/20  15:36
 * @Copyright
 */
public class linkedListDome {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        //-------------------------添加------------------
//        linkedList.addFirst("a");
//        linkedList.addFirst("b");
//        System.out.println("linkedList = " + linkedList);
        //------------------------jdk1.6-------------
        linkedList.offerFirst("a");
        linkedList.offerFirst("b");
        linkedList.offerFirst("c");

        Iterator iterator = linkedList.iterator();
        while (iterator.hasNext()){
            String s =(String) iterator.next();
            System.out.println("s = " + s);
        }


//        System.out.println("linkedList = " + linkedList);

        //-------------------------获取-------------------
//        System.out.println(linkedList.getFirst());//如果链表为空，抛出noSuchElementException
//        System.out.println(linkedList.getLast());

            //jdk1.6
//        System.out.println(linkedList.peekFirst());//如果链表为空，返回null
//        System.out.println(linkedList.peekLast());
//        System.out.println(linkedList);

//        //---------------------------删除----------------------
//        linkedList.removeFirst();
//        linkedList.removeLast();
//
//        //jdk1.6
//        linkedList.peekFirst();
//        linkedList.peekLast();
//        System.out.println("linkedList = " + linkedList);



     /*
     * addfist
     * addlast
     *
     *  //jdk1.6
     * offerfirst  有返回值 boolean
     * offerlast   有返回值 boolean
     *
     * */

    }
}
